   package com.javalong.affairs.base.ui;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.javalong.affairs.R;

public class TextSelectView extends LinearLayout implements OnClickListener {

	private TextView tv_content;
	private ImageView iv_image;


	public TextSelectView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}

	public TextSelectView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TextSelectView(Context context) {
		super(context);
		init();
	}

	private void init() {
		LayoutInflater inflater = LayoutInflater.from(getContext());
		inflater.inflate(R.layout.ui_textselect, this);
		tv_content = (TextView) findViewById(R.id.tv_content);
		iv_image = (ImageView) findViewById(R.id.iv_image);
		iv_image.setOnClickListener(this);
	}

	public void setText(String text) {
		tv_content.setText(text);
	}

	public void setImage(int resId) {
		Drawable draw = getResources().getDrawable(resId);
		iv_image.setImageDrawable(draw);
	}

	public interface OnImageClick {
		void onClick(View view);
	}

	private OnImageClick onImageClick;

	public void setOnImageClick(OnImageClick onImageClick) {
		this.onImageClick = onImageClick;
	}

	@Override
	public void onClick(View v) {
		if (onImageClick != null) {
			onImageClick.onClick(this);
		}
	}
}
